1738C - Even Number Addicts - CodeForces Solution


dp games greedy math

Please click on ads to support us..

Python Code:

def IsAliceWin(EvenCount,OddCount):
    if (OddCount%4) in [0,3]:
        return True
    return ((EvenCount%4) in [1,3]) and (OddCount%4==1)
for _ in range(int(input())):
    EvenCount,OddCount=[0,0]
    input()
    for i in list(map(int,input().split())):
        if i%2==0:
            EvenCount+=1
        else:
            OddCount+=1
    if IsAliceWin(EvenCount,OddCount):
        print("Alice")
    else:
        print("Bob")

C++ Code:

/*
ID: meadri01
LANG: C
TASK: test
*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int 				long long
#define w(t)                int t;cin>>t;while(t--)
#define pb                  push_back
#define mk                  make_pair
#define ascSort(v)          sort(v.begin(), v.end())
#define descSort(v)         sort(v.begin(), v.end(), greater<int>())
#define ff                  first
#define ss                  second
#define pi                  pair<int,int>
#define vi                  vector<int>
#define mi                  map<int,int>
#define fill(a,x)           fill(a.begin(), a.end(), x)
#define iota(a,x)           iota(a.begin(), a.end(), x)
#define umapi               unordered_map<int,int>

#define sz(x)               (int)x.size()
#define all(x)              x.begin(), x.end() 
#define ln                  "\n"

const int mod1=998244353;
const int mod2=1e12+7;
const int inf=mod2;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output1.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

void testcase(){
	int n;cin>>n;
	int odd=0;
	for(int i=0,a; i<n; i++){
		cin>>a;
		odd+=(abs(a)%2==1);
	}
	if(odd%4==0||odd%4==3||(odd%4==1&&(n-odd)%2==1))cout<<"Alice\n";
	else cout<<"Bob\n";
}

int32_t main(){
	
	FIO();
	//usaco("test");
	int t=1;
	cin>>t;
	for(int i=1; i<=t; i++){
		//cout<<"Case #"<<i<<": ";
		testcase();
	}
	return 0;
		
}


Comments

Submit
0 Comments
More Questions

119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity
1627B - Not Sitting
1663C - Pōja Verdon
1497A - Meximization
1633B - Minority
688B - Lovely Palindromes
66B - Petya and Countryside
1557B - Moamen and k-subarrays
540A - Combination Lock
1553C - Penalty
1474E - What Is It